package com.banji.gupiao.controller;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import com.banji.gupiao.manager.GuPiaoDataManager;
import com.banji.gupiao.model.GuPiaoSYL;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.FileOutputStream;
import java.util.List;

@RestController
@RequestMapping("/gupiao/data")
public class GuPiaoDataController {

    @Resource
    private GuPiaoDataManager guPiaoDataManager;

    /**
     * 导出报告期数据
     * @param response
     */
    @GetMapping("/export/bgq")
    public void exportBGQ(HttpServletResponse response) throws Exception {
        List<GuPiaoSYL> list = guPiaoDataManager.export();
        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("股票-市盈率", "股票-市盈率"), GuPiaoSYL.class, list);
        FileOutputStream fos = new FileOutputStream("D:/股票-报告期.xls");
        workbook.write(fos);
        fos.close();
    }

}
